package com.GXKJ.Test.Util;
import cn.hutool.json.JSONUtil;

import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;













import java.io.IOException;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;










public class HttpClientHelper {
	   
	
	
	    public static List<DB_jiemi> send() throws ParseException, IOException{

			List<DB_jiemi> list=HttpClientHelper.send();

	        String body = "";
	        JSONObject EventTraceInput =new JSONObject();
	    	JSONObject a =new JSONObject();
	    	JSONObject b =new JSONObject();
	        EventTraceInput.put("opera","GetDBMonitor");
	        EventTraceInput.put("curPage", "1");
	        EventTraceInput.put("pageSize","10000");
	        EventTraceInput.put("sort",a);
	        EventTraceInput.put("filtersType", "fuzzyquery");
	        EventTraceInput.put("filters",b);
	        
	        
	        String url="http://172.20.1.102/admin.ashx";
	        //创建httpclient对象
	        CloseableHttpClient client = HttpClients.createDefault();
	        //创建post方式请求对象
	        HttpPost httpPost = new HttpPost(url);
	 
	        //装填参数
	        StringEntity s = new StringEntity(EventTraceInput.toString(), "utf-8");
	        s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
	                "application/x-www-form-urlencoded"));
	        //设置参数到请求对象中
	        httpPost.setEntity(s);
	        System.out.println("请求地址："+url);
//	        System.out.println("请求参数："+nvps.toString());
	 
	        //设置header信息
	        //指定报文头【Content-type】、【User-Agent】
//	        httpPost.setHeader("Content-type", "application/x-www-form-urlencoded");
	        httpPost.setHeader("Content-type", "application/x-www-form-urlencoded");
	        httpPost.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
	 
	        //执行请求操作，并拿到结果（同步阻塞）
	        CloseableHttpResponse response = client.execute(httpPost);
	        //获取结果实体
	        HttpEntity entity = response.getEntity();
	        if (entity != null) {
	            //按指定编码转换结果实体为String类型
	            body = EntityUtils.toString(entity, "utf-8");
	        }
	        EntityUtils.consume(entity);
	        //释放链接
	        response.close();
	        //return body;
	        Gson gson = new Gson();
	        Map<String, String> map = new HashMap<>();
	        map = gson.fromJson(body,map.getClass());
	        String ss = JSONUtil.toJsonStr(map.get("data"));
	        List<DB_jiemi> list1 = JSONUtil.toList(ss, DB_jiemi.class);
	        return list1;
	    }
	public static void main(String[] args) throws Exception {
		JSONObject EventTraceInput =new JSONObject();
        EventTraceInput.put("opera","GetDBMonitor");
        EventTraceInput.put("curPage", "1");
        EventTraceInput.put("pageSize","10000");
        EventTraceInput.put("sort",new String[] {});
        EventTraceInput.put("filtersType", "fuzzyquery");
        EventTraceInput.put("filters",new String[] {});

        String url="http://172.20.1.102:80/getdata.ashx";
        System.out.println(send());


	}
	public class DB_jiemi {
		
		
		
		
		private String IP;
		private String DB_USER_S;
		private String DB_PWD_S;
		private String DB_SERVERNAME;
		private String PORT;
		
		
		
		public String getDB_SERVERNAME() {
			return DB_SERVERNAME;
		}
		public void setDB_SERVERNAME(String dB_SERVERNAME) {
			DB_SERVERNAME = dB_SERVERNAME;
		}
		public String getPORT() {
			return PORT;
		}
		public void setPORT(String pORT) {
			PORT = pORT;
		}
		public String getIP() {
			return IP;
		}
		public void setIP(String iP) {
			IP = iP;
		}
		public String getDB_USER_S() {
			return DB_USER_S;
		}
		public void setDB_USER_S(String dB_USER_S) {
			DB_USER_S = dB_USER_S;
		}
		public String getDB_PWD_S() {
			return DB_PWD_S;
		}
		public void setDB_PWD_S(String dB_PWD_S) {
			DB_PWD_S = dB_PWD_S;
		}
		

		
		
	}
	

}

